import { ADD_ITEM, TOGGLE_ITEM, REMOVE_ITEM, INIT_DOTO_LIST } from "../constan";


export default (state, action) => {
    const { type, payload } = action;
    switch (type) {
        case ADD_ITEM:
            return [...state, payload]
        case TOGGLE_ITEM:
            return state.map(v => {
                if (v.id === payload) {
                    return { ...v, completed: !v.completed }
                }
                return v
            })
        case REMOVE_ITEM:
            return state.filter(v => v.id !== payload);
        case INIT_DOTO_LIST:
            return payload;
        default:
            return state
    }
}
